
package artistic;

/**
 *
 * @author Mikael Andersson
 * @author Rurik Högfeldt
 */
public class WorkCanvas extends TiledCanvas{

    private TiledCanvas target;

    public WorkCanvas(TiledCanvas target)
    {
        super(target.getWidth(), target.getHeight());
        this.target = target;
    }

    public void done()
    {
        NormalBlender blender = new NormalBlender();
        
        int gw = Math.min(target.getGridWidth(), this.getGridWidth());
        int gh = Math.min(target.getGridHeight(), this.getGridHeight());
        for(int gy = 0; gy < gh; ++gy)
        {
            for(int gx = 0; gx < gw; ++gx)
            {
                CanvasTile tile = this.getTile(gx, gy);
                if(tile.isChanged())
                {
                    blender.apply(target.getTile(gx, gy), tile);
                    tile.fill(CanvasTile.FillType.TRANSPARENT);
                    tile.setChanged(false);
                }
            }
        }
    }

    public TiledCanvas getTarget()
    {
        return target;
    }

}
